﻿#region Includes

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using ManagerWpf.Properties;

#endregion

namespace ManagerWpf
{
	public class BoolToVisibilityConverter : IValueConverter
	{
		#region IValueConverter Members

		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			if ((bool) value)
				return Visibility.Visible;
			else
				return Visibility.Collapsed;
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			throw new NotImplementedException(Resources.NotImplemented);
		}

		#endregion
	}

	public class NotConverter : IValueConverter
	{
		#region IValueConverter Members

		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			return !(bool) value;
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			throw new NotImplementedException(Resources.NotImplemented);
		}

		#endregion
	}

	public class ComposingConverter : IValueConverter
	{
		private readonly List<IValueConverter> converters = new List<IValueConverter>();

		public Collection<IValueConverter> Converters
		{
			get { return new Collection<IValueConverter>(converters); }
		}

		#region IValueConverter Members

		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			for (int i = 0; i < converters.Count; i++)
			{
				value = converters[i].Convert(value, targetType, parameter, culture);
			}
			return value;
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			for (int i = converters.Count - 1; i >= 0; i--)
			{
				value = converters[i].ConvertBack(value, targetType, parameter, culture);
			}
			return value;
		}

		#endregion
	}
}